const domainName = getApp().globalData.domainName
const header = {'content-type':'application/x-www-form-urlencoded'}
const dataType = 'json'
const method = 'POST'
const responseType = 'text'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  // 练习就业指导
  contact_btn(){
    wx.navigateTo({
      url: '/pages/contact_admin/contact_admin',
    })
  },

  // 前往练题
  go_index(){
    wx.switchTab({
      url:  '/pages/index/index'
    })
  },


  // 拨打电话
  mk_call(){
    wx.makePhoneCall({
      phoneNumber: this.data.recruit_info.contact,
    })
  },

  // 加载招聘信息
  load_recruitment(recruitment_id){
    wx.showLoading({
      title: '网络连接中',
      mask: false,
    })
    wx.request({
      url: domainName + '/load_recruitment',
      data: {
        recruitment_id:recruitment_id,
      },
      dataType: dataType,
      enableCache: true,
      enableHttp2: true,
      enableQuic: true,
      header: header,
      method: method,
      responseType: responseType,
      timeout: 0,
      success: res => {
        wx.hideLoading()
        let recruit_info = res.data.recruit_info
        this.setData({
          recruit_info:recruit_info,
          can_onshow:true,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log('options',options)
    let recruitment_id = options.recruitment_id
    this.setData({
      windowWidth : wx.getSystemInfoSync().windowWidth,
    })
    this.load_recruitment(recruitment_id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      windowHeight:wx.getSystemInfoSync().windowHeight,
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(this.data.can_onshow){
      this.onLoad(this.options)
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.data.recruit_info.title,
      path: '/pages/recruitment/recruitment_show/recruitment_show?recruitment_id=' + this.data.recruit_info.recruitment_id,
    }
  },
})